import { _decorator, Component, Node, AnimationState, Animation } from 'cc';
import { data } from '../data';
import { G } from '../G';
const { ccclass, property } = _decorator;

@ccclass('GetReadyScene')
export class GetReadyScene extends Component {

    idleState : AnimationState

    start() {

        // 获取动画组件
        const animationComponent = this.node.getChildByName("GetReady").getComponent(Animation)

        // 获取动画组件上的动画剪辑
        const [idleClip, runClip] = animationComponent.clips;

        // 获取 idleClip 的动画状态
        this.idleState = animationComponent.getState(idleClip.name);
        
    }

    update() {
        // Get Ready动画结束，进入游戏
        if (!this.idleState.isPlaying) {
            this.onLoadSuccess()
        }
    }

    onLoadSuccess() {
        if (data.gameMode == 1) {
            G.enterClassicModeGame()
        }
        if (data.gameMode == 0) {
            G.enterArcadeModeGame()
        }
    }
}


